@echo off
echo ==========================================
echo 营养系统菜品信息处理最终检查工具
echo ==========================================

echo.
echo 1. 检查定时任务状态...
echo =====================
schtasks /query /tn "营养系统菜品信息自动处理" /fo LIST | findstr "上次运行时间 下次运行时间 状态"

echo.
echo 2. 检查批处理文件...
echo ===================
if exist "D:\wwwroot\yingyang\runtime\run_dish_processing.bat" (
    echo ✓ 批处理文件存在
) else (
    echo ✗ 批处理文件不存在
)

echo.
echo 3. 检查PHP脚本...
echo =================
if exist "D:\wwwroot\yingyang\runtime\auto_process_dish_info.php" (
    echo ✓ PHP脚本存在
) else (
    echo ✗ PHP脚本不存在
)

echo.
echo 4. 测试数据库连接...
echo =====================
cd /d D:\wwwroot\yingyang
php -r "
<?php
try {
    \$config = ['hostname'=>'127.0.0.1', 'database'=>'yingyang', 'username'=>'root', 'password'=>'root', 'charset'=>'utf8mb4'];
    \$dsn = 'mysql:host=' . \$config['hostname'] . ';dbname=' . \$config['database'] . ';charset=' . \$config['charset'];
    \$pdo = new PDO(\$dsn, \$config['username'], \$config['password']);
    echo '✓ 数据库连接成功\n';
} catch (Exception \$e) {
    echo '✗ 数据库连接失败: ' . \$e->getMessage() . '\n';
}
?>
"

echo.
echo 5. 检查未处理菜品数量...
echo =========================
php -r "
<?php
try {
    \$config = ['hostname'=>'127.0.0.1', 'database'=>'yingyang', 'username'=>'root', 'password'=>'root', 'charset'=>'utf8mb4'];
    \$dsn = 'mysql:host=' . \$config['hostname'] . ';dbname=' . \$config['database'] . ';charset=' . \$config['charset'];
    \$pdo = new PDO(\$dsn, \$config['username'], \$config['password']);
    \$stmt = \$pdo->query('SELECT COUNT(*) as count FROM fa_food_dish WHERE ai_called = 0');
    \$result = \$stmt->fetch(PDO::FETCH_ASSOC);
    echo '未处理菜品数量: ' . \$result['count'] . '\n';
} catch (Exception \$e) {
    echo '查询失败: ' . \$e->getMessage() . '\n';
}
?>
"

echo.
echo 最终检查完成。
pause